package com.hqyj.controller;

import com.hqyj.exception.R;
import com.hqyj.pojo.BuyCar;
import com.hqyj.pojo.Item;
import com.hqyj.service.BuyCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/buyCar")
public class BuyCarController {

    @Autowired
    BuyCarService buyCarService;

    /**
     * 添加购物车
     * @param item
     * @param request
     * @return
     */
    @PostMapping("/car")
    public R addBuyCar(@RequestBody Item item, HttpServletRequest request){
        return buyCarService.addBuyCar(item,request);
    }
    /**
     * 展示购物车
     * @param request
     * @return
     */
    @GetMapping("/car")
    public R showBuyCar( HttpServletRequest request){
        return buyCarService.showBuyCar(request);
    }
    /**
     * 更新购物车
     * @param request
     * @return
     */
    @PutMapping("/car")
    public R updateBuyCar(@RequestBody BuyCar buyCar, HttpServletRequest request){

        return buyCarService.updateBuyCar(buyCar,request);
    }
    /**
     * 删除购物车的一条信息
     * @param request
     * @return
     */
    @DeleteMapping("/car")
    public R deleteBuyCar(Integer goodsId, HttpServletRequest request){
        return buyCarService.deleteBuyCar(goodsId,request);
    }
    /**
     * 清空购物车
     * @param request
     * @return
     */
    @DeleteMapping("/car/car")
    public R clearBuyCar(HttpServletRequest request){
        return buyCarService.clearBuyCar(request);
    }


}
